package com.googlecode.tda367.denty.core.data;

import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;

import com.googlecode.tda367.denty.constants.Constants;

public class GameData implements PropertyChangeListener {
	
	private static GameData instance;
	private int hp;
	private int lives;
	private int blocks;
	private int maxBlocks;
	
	private GameData() {
		this.lives = Constants.STARTING_LIVES;
		this.blocks = 0;
		this.setMaxBlocks(0);
		this.hp = Constants.DENTY_MAX_HP;
	}
	
	public static GameData getInstance() {
		if (instance == null) {
			instance = new GameData();
		}
		return instance;
	}

	@Override
	public void propertyChange(PropertyChangeEvent evt) {
		String changedProperty = evt.getPropertyName();
		if (changedProperty == "hp")this.hp = (Integer) evt.getNewValue();
		if (changedProperty == "availableBlocks")this.blocks = (Integer) evt.getNewValue();
		
	}

	public int getHP() {
		return this.hp;
	}

	public int getBlocks() {
		return this.blocks;
	}
	
	public void setBlocks(int blocks) {
		this.blocks = blocks;
	}

	public int getLives() {
		return this.lives;
	}
	
	public void setLives(int lives){
		this.lives = lives;
		this.hp = Constants.DENTY_MAX_HP;
	}

	public void setMaxBlocks(int maxBlocks) {
		this.maxBlocks = maxBlocks;
	}

	public int getMaxBlocks() {
		return maxBlocks;
	}
}
